/**
 * 校验通用类
 */
export class ValidateUtil {

  public static RegNumeric = /^-?\d*(\.\d+)?$/;
  public static RegInteger = /^-?\d+$/;
  public static RegQQ = /^[1-9]\d{4,10}$/;
  public static RegMobile = /^((1[3|4|5|7|8][0-9]{1})+\d{8})$/;
  public static RegPhone = /^0\d{2,3}-?\d{7,8}$/;

  public static isEmpty(source){
    if(source != null && source != undefined && source != 'undefined' && source != "")
      return false;
    return true;
  }

  /** 身份证验证 */
  public static isIdentity(identity){
    let identityCard = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;

    if(identity != null && identity != "" && identityCard.test(identity)){
      return true;
    }
    return false;
  }

  /** 手机号验证 */
  public static isMobile(mobile){
    if(mobile != null && mobile != "" && ValidateUtil.RegMobile.test(mobile)){
      return true;
    }
    return false;
  }

  /** 邮箱验证 */
  public static isEmail(email){
    let verEmail =  /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if(email != null && email != "" && verEmail.test(email)){
      return true;
    }
    return false;
  }

  /** 座机验证 */
  public static isPhone(phone){
    if(phone != null && phone != "" && ValidateUtil.RegPhone.test(phone)){
      return true;
    }
    return false;
  }


}
